﻿@model IEnumerable<BenzInfo.Hockey.Grenadiers.Models.Team>

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">
    $(document).ready(function () {

        $('#dialog_team').dialog({
            autoOpen: false,
            modal: true,
            draggable: false,
            resizable: false,
            width: 580,
            height: 'auto',
            buttons: [
                {
                    id: 'dialog_btn_save', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save',
                    click: function () {
                        $('form', this).submit();
                    }
                },
                {
                    id: 'dialog_btn_cancel', text: '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ]
        });

        $('.team').click(function () {
            var url = $(this).attr('href');
            var title = '';

            if (url.indexOf('Create') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Create';
                $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Create');
            }
            else if (url.indexOf('Edit') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Edit';
                $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Save');
            }
            else if (url.indexOf('Delete') > 0) {
                title = '@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete';
                $('#dialog_btn_save span').html('@BenzInfo.Hockey.Grenadiers.Resources.Dictionary.Delete');
            }

            $('#dialog_team').empty().load(url, function () {
                $('#dialog_team').dialog('option', 'title', title).dialog('open');
            });

            return false;
        });
    });

</script>

<div id="dialog_team"></div>

<h2>Index</h2>

    @if (ViewBag.CurrentUser != null)
    { 
    	<div>
    		<span class="buttons">
    			@Html.ActionLink("Create New", "Create", null, new { @class = "team" })
      	</span>
      </div>
    }      			
</p>
<table cellpadding="5px">
    <tr>
        <th>
            Name
        </th>
        <th>
            Year
        </th>
        <th>
            Logo
        </th>
        <th>
            Picture
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Year)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Logo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Picture)
        </td>
        <td>
        @if (ViewBag.CurrentUser != null)
        {             
	        <div>
	        	<span class="buttons">        
            @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "team" }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { @class = "team" })
	        	</span>
	        </div>
	      }            
        </td>
    </tr>
}

</table>
